#include "mysql_base.h"
#include <iostream>

#include <filesystem>
#include <chrono>
namespace fs = std::filesystem;

#include <boost/json.hpp>

#include <spdlog/spdlog.h>
#include <spdlog/sinks/daily_file_sink.h>

#include "init_spdlog.h"

int main()
{
    try {
        init_spdlog();
        MysqlClient client("0.0.0.0", 3344, "stock_ro", "stock_ro_123", "");
        // client.query("select * from szse_a.t_000001_tick");
        client.query("select * from stock.stock_list");
        auto result = client.result();
        SPDLOG_INFO("{} {}", result->column_names().size(), 
                             result->result().size());
        boost::json::value jv = {
            {"columns", result->column_names()},
            {"result", result->result()}
        };
        SPDLOG_INFO("{}", boost::json::serialize(jv));
        auto &row = result->result()[0];
        std::string trade_time;
        trade_time = std::string(row["listing_date"]);
        SPDLOG_INFO("trade_time {}", trade_time);
        auto name = std::string(row["company_name"]);
        SPDLOG_INFO("name {}", name);
        ////////////////////////////////////////////////////////////////
        client.query("select * from sse_a.t_baostock_daily_k_line where is_st = false limit 100");
        result = client.result();
        jv = {
            {"columns", result->column_names()},
            {"result", result->result()}
        };
        SPDLOG_INFO("{}", boost::json::serialize(jv));
        auto &row_k_line = result->result()[0];
        bool is_st = bool(row_k_line["is_st"]);
        SPDLOG_INFO("isst {}", is_st);
    }
    catch(std::exception &e) {
        SPDLOG_ERROR("{}", e.what());
    }
}
